package org.suburban.servlet;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.IndexOutOfBoundsException;

/**
 * class to remove all non-XML symbols from HTML stream
 * @author Alexey Palamarchuk (slonnik@gmail.com)
 *
 */
public class NormaliseReader extends InputStreamReader{
	
	/**
	 * ctor
	 * @param arg0		- input stream
	 * @param encoding	- encoding
	 */
	public NormaliseReader(InputStream arg0, String encoding) throws UnsupportedEncodingException
	{
		super(arg0, encoding);
	}
	
	@Override
	public int read(char[] buf, int offset, int length) throws IOException,
		IndexOutOfBoundsException
	{
		int count = super.read(buf, offset, length);
		for(int i = 0; i < count; ++i)
		{
			if(buf[i] == '&')
			{
				buf[i] = ' ';
			}
		}
		return count;
	}
	
}
